
import { getOrderList } from '@mall/api/order'
const App = getApp();
import $math from "@src/common/math";
import router from "@src/router";
import base from '@src/store/base'
import { storeBindingsBehavior } from "mobx-miniprogram-bindings";
Component({
  behaviors: [storeBindingsBehavior],
  storeBindings: [{
    store: base,
    fields: ['isiPhoneX', 'themeColor', 'themeTitleColor']
  },],

  /**
   * 组件的属性列表
   */
  properties: {

  },
  options: {
    addGlobalClass: true,
  },

  /**
   * 组件的初始数据
   */
  data: {
    orderFeature: [
      { status: 'ALL', text: '全部' },
      { status: 'WAITING', text: '待付款' },
      { status: 'PAYED', text: '服务中' },
      { status: 'FINISH', text: '已完成' },
    ],
    activeStatus: 'ALL',
    imagesList: [{
      id: 1,
      title: '美妆个护美妆个护美妆个护美妆个护美妆个护',
      img: 'http://f10.baidu.com/it/u=121654667,1482133440&fm=72'
    },
    {
      id: 2,
      title: '美妆个护',
      img: 'http://f10.baidu.com/it/u=121654667,1482133440&fm=72'
    },
    {
      id: 3,
      title: '美妆个护',
      img: 'http://f10.baidu.com/it/u=121654667,1482133440&fm=72'
    }],
    hiddenGoodsList: true,
    orderList: [],
    noData: false,
    barheight: (App.globalData.statusBarHeight) * 2,
    pageNum: 1,
    pageSize: 10,

  },

  /**
   * 组件生命周期
   */
  lifetimes: {

    attached: function (val) {


    },

    moved: function () {

    },
    detached: function () {

    },
  },

  /**
 * 组件所在页面生命周期
 */
  pageLifetimes: {

  },

  /**
   * 组件的方法列表
   */
  methods: {

    onLoad(option) {

      console.log('option', option);
      if (option.status) {
        this.setData({
          activeStatus: option.status
        })
      }
      this.getOrderListFunc()
    },
    switchActive(e) {
      if (e.currentTarget.dataset.status == this.data.activeStatus) { return }
      this.setData({
        activeStatus: e.currentTarget.dataset.status,
        pageNum: 1,
        noData: false,
        orderList: []
      })
      this.getOrderListFunc()
    },
    //获取订单列表
    getOrderListFunc() {
      console.log("执行");
      console.log("this.data.noData", this.data.noData)
      let self = this;
      let query = {
        pageNum: this.data.pageNum,
        pageSize: this.data.pageSize,
        status: this.data.activeStatus == 'ALL' ? ' ' : this.data.activeStatus
      }
      if (this.data.noData) { return; }
      console.log('query', query)
      getOrderList(query).then(res => {
        if (!res.data.hasNextPage) {
          self.setData({
            noData: true
          })
        }
        let list = res.data.list;
        list.forEach(item => {
          if (item.items) {
            item.items.forEach(val => {
              if (typeof (val.skuInfo) == 'string') {
                val.skuInfo = JSON.parse(val.skuInfo)
              }
            })
          }
          if (item.totalFee > 0) {
            item.totalFee = $math.div(item.totalFee, 100)
          }
        })
        self.setData({
          orderList: self.data.orderList.concat(list),
          pageNum: query.pageNum + 1
        })

      })
    },
    examineGoodsList(e) {

      let tempId = e.currentTarget.dataset.id;
      //找到数组id 和点击id匹配的索引
      let activeIndex = this.data.IconAD.findIndex(item => {
        return item.id == tempId
      })
      this.setData({
        ["IconAD[" + activeIndex + "].hiddenGoodsList"]: false
      })


      console.log(this.data.IconAD)
    },
    goDetail(e) {
      console.log("e", e);
      let orderNo = e.currentTarget.dataset.item.orderNo;
      router.push({ name: 'mall/order-detail', params: { orderNo: orderNo } })

    },
    scrolltolower() {
      console.log("触底了")
    }



  }
})
